package com.xuecheng.content.api;

import com.xuecheng.base.exception.ValidationGroups;
import com.xuecheng.base.model.PageParams;
import com.xuecheng.base.model.PageResult;
import com.xuecheng.content.model.dto.AddCourseDto;
import com.xuecheng.content.model.dto.QueryCourseParamsDto;
import com.xuecheng.content.model.dto.UpdateCourseDto;
import com.xuecheng.content.model.po.CourseBase;
import com.xuecheng.content.model.vo.CourseVO;
import com.xuecheng.content.service.CourseBaseInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(value = "课程管理相关接口", tags = "课程管理相关接口")
@RestController
@RequiredArgsConstructor
public class CourseBaseInfoController {

  private final CourseBaseInfoService courseBaseInfoService;

  @ApiOperation("课程查询接口")
  @PostMapping("/course/list")
  public PageResult<CourseBase> list(PageParams page, @RequestBody(required = false) QueryCourseParamsDto dto) {
    PageResult<CourseBase> list = courseBaseInfoService.list(page, dto);
    return list;
  }

  @ApiOperation("课程添加接口")
  @PostMapping("/course")
  public CourseVO add(@RequestBody @Validated(ValidationGroups.Inster.class) AddCourseDto dto) {
    Long companyId = 123L;
    return courseBaseInfoService.add(companyId, dto);
  }

  @ApiOperation("课程查询详情接口")
  @GetMapping("/course/{courseId}")
  public CourseVO getOne(@PathVariable Long courseId) {
    return courseBaseInfoService.getOne(courseId);
  }

  @ApiOperation("课程修改接口")
  @PutMapping("/course")
  public CourseVO update(@RequestBody @Validated(ValidationGroups.Update.class) UpdateCourseDto dto) {
    Long companyId = 123L;
    return courseBaseInfoService.update(companyId, dto);
  }

}
